<?php

use Illuminate\Database\Seeder;
use App\Models\Inspection\Node;

class CircleNodePivotTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
    	$lines = [1,2,3];
    	$circles = [
    		[
    			1,2,3,
			],
			[
				4,5,6,
			],
			[
				7,8,9
			]
		];
    	$nodes = Node::query()->where('project_id', 1)->get();

    	$relations = [];

    	$step = 1440 / (3 * 9 * $nodes->count());

    	$times = \App\Package\Attendance\Time::nodes($step);
		$index = 0;

    	foreach ($lines as $line) {
    		switch ($line) {
				case 1:
					foreach ($circles[0] as $circle) {
						foreach ($nodes as $node) {
							$relations[] = [
								'line_id' => $line,
								'circle_id' => $circle,
								'node_id' => $node->id,
								'time' => $times[$index]
							];
						}
					}
					break;
				case 2:
					foreach ($circles[1] as $circle) {
						foreach ($nodes as $node) {
							$relations[] = [
								'line_id' => $line,
								'circle_id' => $circle,
								'node_id' => $node->id,
								'time' => $times[$index]
							];
						}
					}
					break;
				case 3:
					foreach ($circles[2] as $circle) {
						foreach ($nodes as $node) {
							$relations[] = [
								'line_id' => $line,
								'circle_id' => $circle,
								'node_id' => $node->id,
								'time' => $times[$index]
							];
						}
					}
					break;
				default:
					break;
			}
		}

		DB::table('circle_node_pivot')->insert($relations);
    }
}
